package Operators;

import java.util.ArrayList;
import States.FarmerStates;
import Templates.Operator;

public class FarmerOperators {
	private static ArrayList<Operator<FarmerStates>> farmerOperators=new ArrayList<Operator<FarmerStates>>();
	
	public static ArrayList<Operator<FarmerStates>> returnOperators()
	{

		farmerOperators.add(new MoveWolfLeft());
		farmerOperators.add(new MoveWolfRight());
		farmerOperators.add(new MoveCabbageLeft());
		farmerOperators.add(new MoveCabbageRight());
		farmerOperators.add(new MoveSheepLeft());
		farmerOperators.add(new MoveSheepRight());
		farmerOperators.add(new MoveFarmerLeft());
		farmerOperators.add(new MoveFarmerRight());
		return farmerOperators;
	}
	
	public static class MoveWolfLeft implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
				FarmerStates s2=new FarmerStates(s);
				s2.setLeftWolf(1);
				s2.setRightWolf(0);
				s2.setLeftFarmer(1);
				s2.setRightFarmer(0);
				return s2;

		}
		
		public boolean available(FarmerStates s)
		{
			if (s.getRightFarmer()==1 && s.getRightWolf()==1) 
				if(!(s.getRightCabbage()==1 && s.getRightSheep()==1))
					return true;
			return false;
		}
		
		public String toString()
		{
			return "Moving Wolf Left";
		}
		public int getOperatorNumber()
		{
			return 1;
		}
		
	}
	public static class MoveWolfRight implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
			FarmerStates s2=new FarmerStates(s);
				s2.setLeftWolf(0);
				s2.setRightWolf(1);
				s2.setLeftFarmer(0);
				s2.setRightFarmer(1);
				return s2;

		}
		
		public boolean available(FarmerStates s)
		{
			if (s.getLeftFarmer()==1 && s.getLeftWolf()==1) 
				if(!(s.getLeftCabbage()==1 && s.getLeftSheep()==1))
			return true;
			return false;
			
		}
		
		public String toString()
		{
			return "Moving Wolf Right";
		}
		public int getOperatorNumber()
		{
			return 2;
		}
		
	}
	public static class MoveSheepLeft implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
			FarmerStates s2=new FarmerStates(s);
				s2.setLeftSheep(1);
				s2.setRightSheep(0);
				s2.setLeftFarmer(1);
				s2.setRightFarmer(0);
				
				return s2;

		}
		
		public boolean available(FarmerStates s)
		{

			if (s.getRightFarmer()==1 && s.getRightSheep()==1) 
			return true;
			return false;
			
		}
		
		public String toString()
		{
			return "Moving Sheep Left";
		}
		public int getOperatorNumber()
		{
			return 3;
		}
		
	}
	public static class MoveSheepRight implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
			FarmerStates s2=new FarmerStates(s);
			s2.setLeftSheep(0);
			s2.setRightSheep(1);
			s2.setLeftFarmer(0);
			s2.setRightFarmer(1);
			return s2;

		}
		
		public boolean available(FarmerStates s)
		{
			if (s.getLeftFarmer()==1 && s.getLeftSheep()==1) 
			return true;
			return false;
			
		}
		
		public String toString()
		{
			return "Moving Sheep Right";
		}
		public int getOperatorNumber()
		{
			return 4;
		}
		
	}
	public static class MoveCabbageLeft implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
			FarmerStates s2=new FarmerStates(s);
				s2.setLeftCabbage(1);
				s2.setRightCabbage(0);
				s2.setLeftFarmer(1);
				s2.setRightFarmer(0);
				return s2;

		}
		
		public boolean available(FarmerStates s)
		{
			if (s.getRightFarmer()==1 && s.getRightCabbage()==1) 
				if(!(s.getRightWolf()==1 && s.getRightSheep()==1))
			return true;
			return false;
			
		}
		
		public String toString()
		{
			return "Moving Cabbage Left";
		}
		public int getOperatorNumber()
		{
			return 5;
		}
		
	}
	public static class MoveCabbageRight implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
			FarmerStates s2=new FarmerStates(s);
				s2.setLeftCabbage(0);
				s2.setRightCabbage(1);
				s2.setLeftFarmer(0);
				s2.setRightFarmer(1);
				return s2;

		}
		
		public boolean available(FarmerStates s)
		{
			if (s.getLeftFarmer()==1 && s.getLeftCabbage()==1) 
				if(!(s.getLeftWolf()==1 && s.getLeftSheep()==1))
			return true;
			return false;
			
		}
		
		public String toString()
		{
			return "Moving Cabbage Right";
		}
		public int getOperatorNumber()
		{
			return 6;
		}
		
	}
	
	public static class MoveFarmerRight implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
			FarmerStates s2=new FarmerStates(s);
				s2.setLeftFarmer(0);
				s2.setRightFarmer(1);
				return s2;
		}
		
		public boolean available(FarmerStates s)
		{
			if (s.getLeftFarmer()==1) 
				if(!(s.getLeftWolf()==1 && s.getLeftSheep()==1))
					if(!(s.getLeftCabbage()==1 && s.getLeftSheep()==1))
			return true;
			return false;
			
		}
		
		public String toString()
		{
			return "Moving Farmer Right";
		}		
		public int getOperatorNumber()
		{
			return 7;
		}
		
	}
	public static class MoveFarmerLeft implements Operator<FarmerStates>{
		public FarmerStates execute(FarmerStates s)
		{
			FarmerStates s2=new FarmerStates(s);
				s2.setLeftFarmer(1);
				s2.setRightFarmer(0);
				return s2;
		}
		
		public boolean available(FarmerStates s)
		{
			if (s.getRightFarmer()==1) 
				if(!(s.getRightWolf()==1 && s.getRightSheep()==1))
					if(!(s.getRightCabbage()==1 && s.getRightSheep()==1))
			return true;
			return false;
			
		}
		
		public String toString()
		{
			return "Moving Farmer Left";
		}
		public int getOperatorNumber()
		{
			return 8;
		}
		
	}
	public static class InitialState implements Operator<FarmerStates>
	{
		public String toString(){
	
		return "Initial State";
	}
		
		public int getOperatorNumber()
		{
			return 0;
		}
		
	
	public FarmerStates execute(FarmerStates s)
	{
		return null;
	}
	
	public boolean available(FarmerStates s)
	{
		return false;
		
	}
	
	}
}
